package com.scl.springtalis.controller;

import com.scl.springtalis.polo.Emp;
import com.scl.springtalis.polo.PageBean;
import com.scl.springtalis.polo.Result;
import com.scl.springtalis.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@Slf4j
public class EmpConrtoller {

    @Autowired
    private EmpService empService;
    @GetMapping("/emps")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10")Integer pageSize,
                       String name, Short gender,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        log.info("<UNK>");
        PageBean pageBean =empService.page(page, pageSize,name,gender,begin,end);

        return Result.success(pageBean);
    }
    @DeleteMapping("/emps/{ids}")
    public Result delect(@PathVariable List<Integer> ids){
        log.info("<UNK>");
        empService.delect(ids);
        return Result.success();
    }
    @PostMapping("/emps")
    public Result save( @RequestBody Emp emp){
        log.info("新增员工");
        empService.save(emp);
        return Result.success();
    }
    @GetMapping("/emps/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("<UNK>");
        Emp emp = empService.getById(id);
        return Result.success(emp);
    }
    @PutMapping("/emps")
    public Result update(@RequestBody Emp emp){
        log.info("<UNK>");
        empService.update(emp);
        return Result.success();
    }
}
